package com.wang.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wang.domain.User;
import com.wang.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private IUserService userService;
	@RequestMapping("/index")
	private String list(Model model) {
		model.addAttribute("users", userService.queryAll());
		return "forward:/WEB-INF/jsp/index.jsp";
	}
	@RequestMapping("/input")
	private String input(Long id,Model model) {
		if(id != null){
			model.addAttribute("user", userService.queryOne(id));
		}
		return "forward:/WEB-INF/jsp/input.jsp";
	}
	@RequestMapping("/del")
	private String del(Long id) {
		userService.delete(id);
		return "redirect:/user/index";
	}
	@RequestMapping("/add")
	private String add(User user) {
		userService.add(user);
		return "redirect:/user/index";
	}
}
